#include "stdafx.h"
#include "EffectManager.h"

#include "Log.h"

namespace Cvekas {

EffectManager::EffectManager(D3DDevicePtr device)
	:
device(device)
{
	LOG("EffectManager created");
}

EffectManager::~EffectManager()
{
	LOG("Destroying EffectManager");
}

EffectPtr EffectManager::load(const std::string &name, const std::string &file)
{
	ResourceId id = getUniqueId(name);
	EffectPtr effect(new Effect(id, device, name, file));
	return insert(name, effect, id);
}

void EffectManager::onDeviceLost()
{
	// If resources is empty, resources.begin() throws exception
	if(resources.empty())
		return;

	for(resources_itr = resources.begin(); resources_itr != resources.end(); ++resources_itr)
	{
		EffectPtr effect = *resources_itr;
		if(bool(effect))
			effect->onDeviceLost();
	}
}

void EffectManager::onDeviceReset()
{
	// If resources is empty, resources.begin() throws exception
	if(resources.empty())
		return;

	for(resources_itr = resources.begin(); resources_itr != resources.end(); ++resources_itr)
	{
		EffectPtr effect = *resources_itr;
		if(bool(effect))
			effect->onDeviceReset();
	}
}

} // namespace
